<?php
namespace app\common\modules\user\services;


use app\common\modules\user\model\User;
use think\Exception;

class UserService
{
    public static function getRecord($id, $with = [])
    {
        $query = new User();
        if ($with) {
            $query->with($with);
        }

        return $query->where('id', $id)->find();
    }

    public static function createRecord($data = [])
    {
        $query = new User();

        return $query->save($data);
    }

    public static function getList()
    {

    }

    public static function registerUser($data = [])
    {
        try {
            self::createRecord($data);

            return self::markResult(true, '', []);

        } catch (Exception $exception) {
            return self::markResult(false, $exception->getData());

        }

    }

    public static function markResult(bool $bool, $message = '', $data = [])
    {
        return [
            'status' => $bool,
            'message' => $message,
            'data' => $data
        ];
    }

}